package com.xzq.bizimpl;

import java.util.Date;
import java.util.List;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.xzq.biz.AqiBiz;
import com.xzq.dao.AqiDao;
import com.xzq.entity.Aqi;
import com.xzq.entity.District;
import com.xzq.entity.Page;
@Service("aqiBiz") 
public class AqiBizImpl implements AqiBiz {
	@Inject
	private AqiDao dao;
	private Aqi oldAqi;
	@Override
	public Page findAllAqiByPage(Page page,Integer type) {
		page = dao.findAllAqiByPage(page,type);
		return page;
	}

	@Override
	public Aqi findOneAqi(Aqi aqi) {
		aqi = dao.findOneAqi(aqi);
		return aqi;
	}

	@Override
	public Integer saveAqi(Aqi aqi) {
		Date date = new Date(System.currentTimeMillis());
		aqi.setLast_modify_time(date);
		District dis = findOneDis(aqi.getDis());
		aqi.setDis(dis);
		Integer count = dao.saveAqi(aqi);
		return count;
	}

	@Override
	public Integer modifyAqi(Aqi aqi) {
		oldAqi = findOneAqi(aqi);
		oldAqi.setMonitor_time(aqi.getMonitor_time());
		oldAqi.setMonitoring_station(aqi.getMonitoring_station());
		District dis = findOneDis(aqi.getDis());
		oldAqi.setDis(dis);
		oldAqi.setPm10(aqi.getPm10());
		oldAqi.setPm2p5(aqi.getPm2p5());
		oldAqi.setLast_modify_time(new Date(System.currentTimeMillis()));
		Integer count = dao.modifyAqi(oldAqi);
		return count;
	}

	@Override
	public Integer deleteAqi(Aqi aqi) {
		aqi = findOneAqi(aqi);
		Integer count = dao.deleteAqi(aqi);
		return count;
	}

	@Override
	public List<District> findAllDis() {
		List<District> list = dao.findAllDis();
		return list;
	}

	@Override
	public District findOneDis(District dis) {
		dis = dao.findOneDis(dis);
		return dis;
	}

	@Override
	public Integer saveDis(District dis) {
		dis.setAqis(null);
		Integer count = dao.saveDis(dis);
		return count;
	}

	@Override
	public Integer modifyDis(District dis) {
		District newdis = findOneDis(dis);
		newdis.setName(dis.getName());
		Integer count = dao.modifyDis(newdis);
		return count;
	}

	@Override
	public Integer deleteDis(District dis) {
		dis = findOneDis(dis);
		Integer count = dao.deleteDis(dis);
		return count;
	}

	@Override
	public Page findAllDisByPage(Page page, String likename) {
		page = dao.findAllDisByPage(page, likename);
		return page;
	}

}
